home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Scheduling / Cassandra / Source / calendar.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-27  |  7.5 KB  |  209 lines

  1. //
  2. // calendar.h
  3. // Copyright (c) 1989, 1990 by Jiro Nakamura 
  4. // All rights reserved
  5. //
  6. // Calendar routine package prototypes.
  7. // Actual functions in calendar.m
  8. //
  9. // Note: These are collected from various sources. They may have
  10. // the infamous 1670 bug (or whenever it was). Use only for
  11. // dates that are current (1900+).
  12. //
  13. // RCS Information
  14. // Revision Number->    $Revision: 1.12 $
  15. // Last Revised->    $Date: 90/10/27 17:44:09 $
  16. //
  17.  
  18. #import <time.h>
  19. #import <stdio.h>
  20.  
  21. #define    SEC        TRUE
  22. #define    NOSEC    FALSE
  23.  
  24. /*
  25.     extern const int ayear[13];
  26.     extern const char *months[12];
  27.     extern const char *shortMonths[12];
  28.     extern const char *shortWeekDays[7];
  29.     extern const char *weekDays[7];
  30.  
  31. */
  32.  
  33. // Procedure:        int jan1( int year)
  34. // Arguments:        int year-> the year in question (e.g., 1970, 1971)
  35. // Description:        Returns what day of the week the first day
  36. //            of the year <year> will  be. 
  37. //            (i.e., Jan 1st, <year> will be .......)
  38. // Returns:        an integer from 0..6. (0=Sunday.....6=Saturday)
  39. int jan1( int);
  40.  
  41.  
  42. // Procedure:        int daysInMonth( int month, int year)
  43. // Arguments:        int month, int year ->    the month and year in question
  44. // Description:        Returns the number of days in the month and year in question
  45. // Return Value:    The number of days in <month> of <year>.
  46. int daysInMonth(int,int);
  47.  
  48.  
  49. // Procedure:        int daysInYear( int year)
  50. // Arguments:        int year ->    the year in question
  51. // Description:        Returns the number of days in the year in question
  52. // Return Value:    The number of days in <year>.
  53. int daysInYear(int);
  54.  
  55.  
  56. // Procedure:        int addOne(int month, int year)
  57. // Arguments:        the month and year in question
  58. // Description:        This is a support function. It returns 1 if
  59. //            after the date in question, 1 must be added
  60. //            for leap years. 
  61. // Return Value:    1 if the date is in the year of a leap year,
  62. //            and after Feb 29, 0 if it is not a leap year
  63. //            or it is before Feb 28.
  64. int addOne( int, int);
  65.  
  66.  
  67. // Procedure:        int daysUpTo(int month, year)
  68. // Arguments:        the date in question
  69. // Description:        Returns how many days it has been since
  70. //            Jan 1 to the beginning of this month.
  71. // Return Value:    0 - 365
  72. int daysUpTo(int,int);
  73.  
  74.  
  75. // Procedure:        int firstDayOf( int month, int year)
  76. // Arguments:        the date in question
  77. // Description:        Returns what day of the week the month
  78. //            in question starts with.
  79. // Return Value:    an integer from 0..6. (0=Sunday.....6=Saturday)
  80. int firstDayOf(int,int);
  81.  
  82.  
  83. // Procedure:        int wday( int day, int month,  int year)
  84. // Arguments:        the <day>, <month> and <year> of the date in question
  85. // Description:        Returns the day of the week of the particular date.
  86. //                See ctime(3) for a proper definition of wday.
  87. // Return Value:    an integer from 0..6. (0=Sunday.....6=Saturday)
  88. int wday(int,int,int);
  89.  
  90.  
  91. // Procedure:        int yday( int day, int month,  int year)
  92. // Arguments:        the <day>, <month> and <year> of the date in question
  93. // Description:        Returns the index of the date into the year
  94. //                See ctime(3) for a proper definition of yday.
  95. // Return Value:    an integer from 0..365 (366).  0= Jan 1st xxxx, 365(366) = Dec 31, xxxx
  96. int yday(int,int,int);
  97.  
  98.  
  99. // Procedure:        int printCalendar( int month, int year,  
  100. //                NXStream *stream)
  101. // Arguments:        the date in question and an open stream    
  102. // Description:        printCalendar will print a monthly calendar like
  103. //            cal(1) for the month and year in question and will
  104. //            dump it to the stream <steram>. 
  105. // Return Value:    0 if an error occured, 1 if all successful.    
  106. int printCalendar(int month, int year, NXStream *stream);
  107.  
  108.  
  109. // Procedure:        int printCalendarRTF(int day, int month, 
  110. //                int year,  NXStream *stream
  111. //            char *fontName, float fontSize)
  112. // Arguments:        the date in question and a stream    
  113. // Description:        printCalendarRTF will a RTF version of 
  114. //            a monthly calendar like printCalendar.
  115. //            The day will be highlighted.
  116. // Return Value:    0 if an error occured, 1 if all successful.    
  117. int printCalendarRTF(int day, int month, int year, NXStream *stream,
  118.             char *fontName, float fontSize);
  119.  
  120.  
  121. // Procedure:    ascMyTime(struct tm *time, BOOL showSeconds, BOOL militaryTime)
  122. // Arguments:    struct tm *time     -> the particular time you want printed
  123. //        (BOOL) showSeconds    -> whether you want seconds printed
  124. //        (BOOL) militaryTime    -> whether you want 24hr or am/pm time
  125. // Description:    ascMyTime converts the time structure <time> into an
  126. //         ascii string in the format:
  127. //        seconds showing->    Mon Jan 11, 1990    5:11:30 pm
  128. //         seconds hidden->    Mon Jan 11, 1990    5:11 pm
  129. //        <showSeconds> is either TRUE (showing) or FALSE (hidden)
  130. //        militaryTime is either TRUE or FALSE.
  131. // Return value:A constant character pointer to the converted string.
  132. const char * ascMyTime(struct tm *, BOOL showSeconds,  BOOL militaryTime);
  133.  
  134. // Procedure:    ascMyDate(struct tm *time)
  135. // Arguments:    struct tm *time     -> the particular date you want printed
  136. // Description:    ascMyDate converts the time structure <time> into an
  137. //         ascii string in the format:
  138. //            Mon Jan 11, 1990   
  139. // Return value:A constant character pointer to the converted string.
  140. const char * ascMyDate(struct tm *);
  141.  
  142.  
  143. // Procedure:    monthFromAscii( char *string)
  144. // Arguments:    char *string        -> the string to analyze
  145. // Description:    monthFromAscii tries its darn hardest to figure out what
  146. //        month <string> refers to. It can understand:
  147. //        jan, Jan, JaN, jAN   ->  mean month 1.
  148. //        1             ->  means month 1.
  149. //              Thats it! Pretty stupid routine, huh.
  150. // Return Value: The month (an integer) from 1-12.
  151. int monthFromAscii(char *);
  152.  
  153.  
  154. // Procedure:    calAsciiCmp( char *a, char *b)
  155. // Scope:    To be used only internally by monthFromAscii
  156. // Arguments:    char *a, char *b
  157. // Description:    Compares string <a> to string <b>, but ignores case
  158. // Return Value: 0 if <a> is the same as <b>    
  159. //        -1 if <a> is before <b> (alphabetically)
  160. //         1 if <a> is behind <b> (alphabetically)
  161. int calAsciiCmp( char * , char * );
  162.  
  163.  
  164. // Procedure:        double secondsBetween( struct tm *a, struct tm* b)
  165. // Arguments:        struct tm *a, *b
  166. // Description:        This will compare the time structures <a> to <b> 
  167. //            and return the number of seconds between the two. 
  168. // Return Value:    The number of seconds seperating the two.
  169. //            Positive if <b> is greater than <a>, 
  170. //            negative if <a> is greater, and 0 if they are the same.
  171. double secondsBetween( struct tm * a, struct tm* b);
  172.  
  173.  
  174. // Procedure:        int timeCompare( struct tm *a, struct tm *b)
  175. // Arguments:        time structure <a> and time structure <b>
  176. // Description:        Compares time structure <a> to <b>.
  177. // Return Value:    an integer->     -1 if <a> is smaller than <b>
  178. //                     0 if <a> is equal to <b>
  179. //                     1 if <a> is greater than <b>
  180. int timeCompare(struct tm *a, struct tm *b);
  181.  
  182. // Procedure:        int dayCompare( struct tm *a, struct tm *b)
  183. // Arguments:        time structure <a> and time structure <b>
  184. // Description:        Compares time structure <a> to <b>.
  185. // Return Value:    an integer->     -1 if <a> is smaller than <b>
  186. //                     0 if <a> is equal to <b>
  187. //                     1 if <a> is greater than <b>
  188. int dayCompare(struct tm *a, struct tm *b);
  189.  
  190.  
  191. // Procedure:        (void) fixTmStructure( struct tm *ts)
  192. // Arguments:        struct tm *ts  -> the time structure to "fix"
  193. // Description:        This will go through and make sure the time 
  194. //            structure is in perfect shape, fix wday 
  195. //            and yday, and allow you to do atrocious 
  196. //            things like:
  197. //                ts.tm_mday += 10;
  198. //            and then fix the structure back up by calling
  199. //            fixTmStructure( &ts)
  200. // Return Value:    void
  201. void fixTmStructure( struct tm *ts);
  202.  
  203. // Procedure:        const struct tm *timeNow()
  204. // Description:        Returns a pointer to a structure which contains the 
  205. //            present time
  206. // Return Value:    (struct tm *) -> a pointer to the structure
  207. const struct tm *timeNow();
  208.  
  209.